﻿using System;
using System.IO;
using Assist;
using Autodesk.Revit.DB;
using YArchitech.LIB;
using YArchitech.Revit;

namespace YJKRevitDimensionText.OneKeyPlanDim.Utility
{
	public class LevelDimData
	{
		public LevelDimData(Autodesk.Revit.DB.Document doc)
		{
			this.m_doc = doc;
		}

		public XYZ PtDimLocation
		{
			set
			{
				this.m_PtDimLocation = value;
			}
		}

		public string DimVal
		{
			set
			{
				this.m_strDimVal = value;
			}
		}

		public FamilySymbol GetLevelDimFamilySymbol()
		{
			Transaction transaction = new Transaction(this.m_doc, "CreateDim");
			try
			{
				transaction.Start();
				string strFamilyFilePath = Path.Combine(Product.FamilyLocation, RevitVersion.Version, "OneKeyDim", "标高、坡道族、尺寸标注.rvt");
				LevelDimData.m_familySymbol = FindFamilySymbol.GetFamilySymbol(this.m_doc, strFamilyFilePath, LevelDimData.m_strFamilyName, LevelDimData.m_strFamilySymbolName);
				transaction.Commit();
			}
			catch
			{
				transaction.RollBack();
			}
			return LevelDimData.m_familySymbol;
		}

		public FamilyInstance CreateLevelDim()
		{
			AnnotationSymbol annotationSymbol = null;
			Transaction transaction = new Transaction(this.m_doc, "CreateDim");
			try
			{
				transaction.Start();
				if (LevelDimData.m_familySymbol == null)
				{
					transaction.RollBack();
				}
				AnnotationSymbolType annotationSymbolType = LevelDimData.m_familySymbol as AnnotationSymbolType;
				annotationSymbol = RevitVersionFuncs.NewAnnotationSymbol(this.m_doc, this.m_PtDimLocation, annotationSymbolType, this.m_doc.ActiveView);
				Parameter parameter = RevitElementExtension.GetParameter(annotationSymbol, "标高1");
				if (parameter != null && this.m_strDimVal != "")
				{
					parameter.Set(this.m_strDimVal);
				}
				transaction.Commit();
			}
			catch
			{
				transaction.RollBack();
			}
			return annotationSymbol;
		}

		public static FamilySymbol m_familySymbol = null;

		public static string m_strFamilyFilePath = "C:\\Users\\zk\\Desktop\\标高、坡道族、尺寸标注.rvt";

		public static string m_strFamilyName = "符号_一键平面图_标高标注";

		public static string m_strFamilySymbolName = "标准";

		private XYZ m_PtDimLocation = XYZ.Zero;

		private string m_strDimVal = string.Empty;

		private Document m_doc;
	}
}
